namespace Xmef.Serializer.Internal
{
    using System;
    using System.Collections;
    using System.Xml.Serialization;

    [Serializable]
    internal class XmlSerializerCache
    {
        private readonly Hashtable hashtable = new Hashtable();

        internal bool Override(IXmlRuntimeSerializerInternal key, XmlSerializer serializer)
        {
            if (this.hashtable.ContainsKey(key))
            {
                this.hashtable[key] = serializer;
                return true;
            }
            return false;
        }

        public XmlSerializer this[IXmlRuntimeSerializerInternal key]
        {
            get
            {
                XmlSerializer serializer = null;
                if (!this.hashtable.ContainsKey(key))
                {
                    serializer = key.RuntimeSerializer;
                    this.hashtable[key] = serializer;
                    return serializer;
                }
                return (XmlSerializer) this.hashtable[key];
            }
        }
    }
}

